import Vue from "vue";
import VueRouter from "vue-router";
import Login from "@/views/Login";
import Home from "@/views/Home";
import Product from "@/views/Product";
import Book from "@/views/Books";
import Classic from "@/views/Classic";
import Agricultrue from "@/views/Agricultrue";
import ProductDetail from "@/components/ProductDetail";

Vue.use(VueRouter);

// 配置路由表
const routes = [
  {
    path: "/",
    redirect: "/product", // 根路径重定向到 /product
  },
  {
    path: "/login",
    name: "login",
    component: Login,
  },
  {
    path: "/",
    name: "home",
    component: Home,
    children: [
      {
        path: "/product",
        component: Product,
      },
      {
        path: "/classic",
        component: Classic,
      },
      {
        path: "/agricultrue",
        component: Agricultrue,
      },
      {
        path: "/book",
        component: Book,
      },
      {
        path: "/detail/:id",
        component: ProductDetail,
        props: true,
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});

export default router;
